var regexp = {
		COST : /^[0-9_]+$/
};

function isValidName(form) {
    var name = form["name"].value;
    if(name == "" || name == null){
            return false;
    } 
    return true;
}

function isValidFrom(form) {
    var from = form["from"].value;
    if(from == "" || from == null){
            return false;
    } 
    return true;
}

function isValidTo(form) {
    var to = form["to"].value;
    if(to == "" || to == null){
            return false;
    } 
    return true;
}

function isValidCost(form) {
    var cost = form["cost"].value;
    if(cost == "" || cost == null){
            return false;
    } 
    return regexp.COST.test(cost);
}

function validate()
{
	isValid = new Boolean(true);
	var form = document.form;
	
	if(!isValidName(form)){
	    isValid = false;
	    document.getElementById("errorName").style.display='block';
	} else {
        document.getElementById("errorName").style.display='none';
    }
	
	if(!isValidFrom(form)){
	    isValid = false;
	    document.getElementById("errorFrom").style.display='block';
	} else {
        document.getElementById("errorFrom").style.display='none';
    }
	
	if(!isValidTo(form)){
	    isValid = false;
	    document.getElementById("errorTo").style.display='block';
	} else {
        document.getElementById("errorTo").style.display='none';
    }
	
	if(!isValidCost(form)){
	    isValid = false;
	    document.getElementById("errorCost").style.display='block';
	} else {
        document.getElementById("errorCost").style.display='none';
    }
	
	
	if(isValid == false){
	    event.preventDefault();
	    return false;
	}
	else
	{
		form.submit;
	}
}
